package org.inet.minispring.bean.beandefinition;

import java.util.*;

public class PropertyValues {

    private final List<PropertyValue> propertyValueList = new ArrayList<>();

    public PropertyValues() {}

    public int size() {
        return propertyValueList.size();
    }

    public void addPropertyValue(PropertyValue propertyValue) {
        propertyValueList.add(propertyValue);
    }

    public void addPropertyValue(String propertyName, String propertyValue) {
        addPropertyValue(new PropertyValue(propertyName, propertyValue));
    }

    public void removePropertyValue(PropertyValue target) {
        propertyValueList.remove(target);
    }

    public void removePropertyValue(String propertyName) {
        propertyValueList.removeIf(v -> Objects.equals(propertyName, v.getName()));
    }

    public PropertyValue[] getPropertyValues() {
        return propertyValueList.toArray(new PropertyValue[this.propertyValueList.size()]);
    }

    public PropertyValue getPropertyValue(String propertyName) {
        var result = propertyValueList.stream().filter(v -> propertyName.equals(v.getName())).findFirst();
        return result.orElse(null);
    }

    public Object get(String propertyName) {
        var pv = Optional.of(getPropertyValue(propertyName));
        return pv.orElse(null);
    }

    public boolean contains(String propertyName) {
        return getPropertyValue(propertyName) != null;
    }

    public boolean isEmpty() {
        return propertyValueList.isEmpty();
    }
}
